package cn.jyc.ssm03.service;

import cn.jyc.ssm03.dao.CustCount01Mapper;
import cn.jyc.ssm03.pojo.CustCount01;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CustCountService {
    @Autowired
    private CustCount01Mapper ccm;

    public List<CustCount01> qry01(){
        return ccm.qry01();
    }

    public List<CustCount01> qry02(){
        List<CustCount01> ress = ccm.qry02();
        Double q1 = Double.valueOf(String.valueOf(ress.get(0).getValue()));
        Double q2 = Double.valueOf(String.valueOf(ress.get(1).getValue()));
        System.out.println("q1:"+q1);
        System.out.println("q2:"+q2);
        ress.get(0).setValue(Math.round((q1/(q1+q2))*100));
        ress.get(1).setValue(Math.round((q2/(q1+q2))*100));
        return ress;
    }

    public List<List<Object>> qry03(){
        List<CustCount01> ccs = ccm.qry03();
        List<List<Object>> res = new ArrayList<>();
        for (CustCount01 cc : ccs) {
            List<Object> re = new ArrayList<>();
            re.add(cc.getName());
            re.add(cc.getValue());
            res.add(re);
        }
        return res;
    }

    public List<List<Object>> qry04(String bgdt,String fndt){
        List<CustCount01> ccs = ccm.qry04(bgdt,fndt);
        List<List<Object>> res = new ArrayList<>();
        for (CustCount01 cc : ccs) {
            List<Object> re = new ArrayList<>();
            re.add(cc.getName());
            re.add(cc.getValue());
            res.add(re);
        }
        return res;
    }
}
